//
//  MTTabbarViewController.m
//  Travel
//
//  Created by lanou3g on 15/11/18.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "MTTabbarViewController.h"
#import "MTableViewController.h"

#import "MTNavViewController.h"
#import "MainViewController.h"

#import "MTSelfMenuVC.h"
#import "YRSideViewController.h"


@interface MTTabbarViewController ()


@end

@implementation MTTabbarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initChildControllers];


}

#pragma mark --初始化子视图控制器

-(void)initChildControllers
{
    //首页

    MTableViewController *mVC = [MTableViewController new];
    [self addChildVc:mVC title:@"云游" image:@"iconfont-fenxiang" selectedImage:@"iconfont-fenxiang"];
    
    //推荐
//    STableViewController *sVC = [STableViewController new];
//    
//    [self addChildVc:sVC title:@"推荐" image:@"iconfont-svg28" selectedImage:@"iconfont-svg28"];
    
    MainViewController *VC = [MainViewController new];
    [self addChildVc:VC title:@"推荐" image:@"iconfont-svg28" selectedImage:@"iconfont-svg28"];
    //我的
    UTableViewController *uVC = [UTableViewController new];
    [self addChildVc:uVC title:@"我" image:@"iconfont-yonghu" selectedImage:@"iconfont-yonghu"];
   
}


#pragma  mark  -- 添加子视图控制器的方法

/**
 *  添加一个子控制器
 *
 *  @param childVc       子控制器
 *  @param title         标题
 *  @param image         图片
 *  @param selectedImage 选中的图片
 */
- (void)addChildVc:(UIViewController *)childVc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    // 设置子控制器的文字
    childVc.title = title; // 同时设置tabbar和navigationBar的文字
       childVc.tabBarItem.title = title; // 设置tabbar的文字
        childVc.navigationItem.title = title; // 设置navigationBar的文字
    
    // 设置子控制器的图片
    childVc.tabBarItem.image = [UIImage imageNamed:image];
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 设置文字的样式
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = [UIColor cyanColor];
    NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
    selectTextAttrs[NSForegroundColorAttributeName] = [UIColor orangeColor];
    [childVc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [childVc.tabBarItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
    // 先给外面传进来的小控制器 包装 一个导航控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:childVc];
    // 添加为子控制器
    [self addChildViewController:nav];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
   
}


@end
